package com.xiaoniu.mc;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @类描述：
 * @创建人：林继丰
 * @创建时间：2017/9/8 15:12
 * @版权：Copyright (c) 深圳市牛鼎丰科技有限公司-版权所有.
 */
public class Service {

    @HystrixCommand(fallbackMethod = "okFallback", threadPoolProperties = {
            @HystrixProperty(name = "coreSize", value = "30"),
            @HystrixProperty(name = "maxQueueSize", value = "100"),
            @HystrixProperty(name = "queueSizeRejectionThreshold", value = "20")},
            commandProperties = {
                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "100"),
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "50")
            })
    public String ok() throws Exception {
        int l = new Random().nextInt(20000);
        TimeUnit.MILLISECONDS.sleep(l);
        return "ok";
    }

    public String okFallback(Throwable e) {
        System.out.println("execute okFallback!" + e.getMessage());
        return "fallback";
    }
}
